<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:h="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>注册</title>
    <style type="text/css" rel="stylesheet">
        .wrap{margin:0 auto;width:400px;}
    </style>
    <script th:src="@{/js/jquery-1.8.3.js}"></script>
    <script type="text/javascript">
    function check() {
        if($("input[name='name']").val()==""){
            alert("用户名不能为空");
            return false;
        }
        else if($("input[name='password']").val()==""){
            alert("密码不能为空");
            return false;
        }else {
            return true;
        }
    }
    function reg() {
        var params={
            name:$("input[name='name']").val(),
            password:$("input[name='password']").val()
        };

     $.ajax({
         type: "Post",
         url: "/regcon",
         data:JSON.stringify(params),
         contentType: "application/json; charset=utf-8",
         success:function (data) {
         var result = data.toString();
         if(result == "success"){
             alert("注册成功,请去登陆");
             window.location.href="/login";
         }else if (result == "error"){
             alert("账号已存在，请登录");
             window.location.href="/login"
         }else {
             alert("注册失败，请填写注册信息")
         }

         },error:function (data) {
             alert("后台处理异样");
             window.location.href="/reg"
         }
     });
    }
    function rest() {
        $("#name").val("");
        $("#password").val("");
    }
    </script>
</head>
<body>
<div class="wrap">
    <h1 align="center">注册界面</h1>
    <fieldset>
        <p>用户名: <input type="text" id="name" name="name"/></p>
        <p>密&nbsp;&nbsp;&nbsp;&nbsp;码: <input type="text" id="password" name="password"/></p>
        <p><input type="button" onclick="reg()" value="注册"/>&nbsp;&nbsp;&nbsp;<input type="button" onclick="rest()" value="取消" /></p>
    </fieldset>
</div>
<div>

</div>
</body>
</html>